package com.masterlu.leetcode.daily.heap.simple;

import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;

/**
 * 剑指 Offer 40. 最小的k个数
 * https://leetcode-cn.com/problems/zui-xiao-de-kge-shu-lcof/
 *
 * @date created in 2021/5/25 9:02
 */
public class Offer40GetLeastNumbers {


    public  int[] getLeastNumbers(int[] arr, int k) {

        int[] targetArr = new int[k];

        PriorityQueue<Integer> queue = new PriorityQueue<Integer>();
        for (int i : arr) {
            queue.offer(i);
        }

        for (int i = 0; i < k; i++) {
            targetArr[i] = queue.poll();
        }

        return targetArr;
    }

}
